package com.example.calendar.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.calendar.ui.components.CalendarBottomBar
import com.example.calendar.ui.theme.CalendarTheme
import dagger.hilt.android.AndroidEntryPoint

/**
 * Main activity for the Calendar application
 */
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            CalendarTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    CalendarApp()
                }
            }
        }
    }
}

/**
 * Top-level composable for the Calendar app
 */
@Composable
fun CalendarApp() {
    val navController = rememberNavController()
    
    // Get current route
    val navBackStackEntry by navController.currentBackStackEntryAsState()
    val currentRoute = navBackStackEntry?.destination?.route ?: Screen.Month.route
    
    // Determine if bottom bar should be shown
    val shouldShowBottomBar = when {
        currentRoute.startsWith("event/") -> false
        currentRoute.startsWith("task/detail/") -> false
        currentRoute.startsWith("task/edit/") -> false
        currentRoute.startsWith("task/create") -> false
        else -> true
    }
    
    Scaffold(
        bottomBar = {
            if (shouldShowBottomBar) {
                CalendarBottomBar(
                    navController = navController,
                    currentRoute = currentRoute
                )
            }
        }
    ) { innerPadding ->
        CalendarNavHost(
            navController = navController,
            modifier = Modifier.padding(innerPadding)
        )
    }
} 